<template>
  <!-- 使用封装后的搜索栏组件 -->
  <SearchBar
      v-bind="$props"
      v-on="$attrs"
  />

  <AsyncTable
      v-bind="$props"
      v-on="$attrs"
  >
    <!-- 统一透传所有插槽 -->
    <template v-for="(_, slotName) in $slots" #[slotName]="scope">
      <slot :name="slotName" v-bind="scope"/>
    </template>
  </AsyncTable>
</template>

<script setup lang="ts">
import {type PropType} from 'vue';
import SearchBar from "@/components/SearchBar/index.vue";
import AsyncTable from "@/components/AsyncTable/index.vue";
import type {SearchItem} from "@/types/search.ts";
import type {TableColumn} from "@/types/table.ts";

interface TreeConfig {
  rowKey: string;
  treeProps: {
    children: string;
    hasChildren?: string;
  };
}

// 定义类型
type FetchDataFunction = () => Promise<{ list: any[]; total: number }>;

// 定义参数
const props = defineProps({
  fetchData: {
    type: Function as unknown as PropType<FetchDataFunction>,
    required: true
  },
  columns: {
    type: Array as PropType<TableColumn[]>,
    required: true
  },
  currentPage: {
    type: Number,
    default: 1
  },
  pageSize: {
    type: Number,
    default: 10
  },
  pageSizes: {
    type: Array as PropType<number[]>,
    default: () => [10, 20, 30, 50]
  },
  queryParams: {
    type: Object,
    required: true
  },
  searchItems: {
    type: Array as PropType<SearchItem[]>,
    required: true
  },
  defaultShownCount: {
    type: Number,
    default: 3
  },
  showPagination: {
    type: Boolean,
    default: true
  },
  isTreeTable: {
    type: Boolean,
    default: false
  },
  treeConfig: {
    type: Object as PropType<TreeConfig>,
    default: () => ({
      rowKey: 'id',
      treeProps: {
        children: 'children',
        hasChildren: 'hasChildren'
      }
    })
  }
});

// 明确定义Emits（确保事件类型安全）
defineEmits<{
  (e: 'search', params: Record<string, any>): void
}>();

// 定义你的插槽类型
defineSlots<{
  default?: (props: { row: any }) => any;
  'action-column'?: (props: { row: any }) => any;
}>();

</script>

<style scoped lang="scss">
@import "index.scss";
</style>